package com.woniuxy.carType.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.carType.model.entity.Car;
import com.woniuxy.carType.service.CarService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/car")
public class carController {
    @Autowired
    private CarService carService;

    @PostMapping("/list")
    public ResponseEntity<Page<Car>> list(@RequestBody Map<String, Integer> params) {
        int pageNum = params.get("pageNum");
        int pageSize = params.get("pageSize");
        Page<Car> page = carService.list(pageNum, pageSize);
        return ResponseEntity.ok(page);
    }

    @PostMapping("/findByType")
    public ResponseEntity<Page<Car>> findByType(@RequestBody Map<String, Integer> params) {
        int pageNum = params.get("pageNum");
        int pageSize = params.get("pageSize");
        int typeId = params.get("typeId");
        Page<Car> page = carService.findByType(pageNum, pageSize, typeId);
        return ResponseEntity.ok(page);
    }



}
